package Work01;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.util.List;

public class demo01 {
    public static void main(String[] args)throws Exception {
        //读取xml文件
        Document document = new SAXReader().read("D:\\cy-javaEE-project\\day01-xml-json\\src\\Work01\\students.xml");
        System.out.println(document);

        //得到根节点
        Element rootElement = document.getRootElement();
        List<Element> elements = rootElement.elements();
        System.out.println("Element Name:"+rootElement.getName());
        for (Element element : elements) {
            System.out.println("Element Name:"+element.getName());
            for (Element ele : (List<Element>) element.elements()) {
                System.out.println("Element Name:"+ele.getName());
                System.out.println("Element Content:"+ele.getText());
            }
        }
    }
}
